﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BPM.ViewModel;
using BPM.Service;
using BPM.Common;

namespace BPM.Controllers
{
    public class RegisterController : BaseController
    {
        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult Register()
        {
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ViewResult Register(RegisterViewModel registerModel)
        {
            Entity.User user = null;
            var svc = new UserService();
            Result result = svc.AddUser(registerModel.UserName, registerModel.RealName, registerModel.Password, out user);

            if (result.Success)
            {
                return View("AfterRegister", registerModel);
            }
            else
            {
                registerModel.Message = result;
                return View(registerModel);
            }
        }
    }

    public class RegisterControllerActions : ControllerDefinition<RegisterController>
    {
        public readonly string Register = "Register";
    }
}
